package com.zecan.rabbitmq.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: lenovo
 * \* Date: 2022/4/21
 * \* Time: 12:03
 * \* Description:
 * \
 */
@Configuration
public class PriorityConfig {

    public static final String PRIORITY_EXCHANGE_NAME = "priority.exchange";
    public static final String PRIORITY_QUEUE_NAME = " priority.name";
    public static final String PRIORITY_ROUTING_KEY = "priority.key";

    @Bean
    public Queue priorityQueue() {
        //创建队列并限制最大的优先级为10
        return QueueBuilder.durable(PRIORITY_QUEUE_NAME).withArgument("x-max-priority", 10).build();
    }

    @Bean
    public DirectExchange priorityExchange() {
        return ExchangeBuilder.directExchange(PRIORITY_EXCHANGE_NAME).build();
    }

    @Bean
    public Binding bindingPriority(DirectExchange priorityExchange,
                                   Queue priorityQueue) {
        return BindingBuilder.bind(priorityQueue).to(priorityExchange).with(PRIORITY_ROUTING_KEY);
    }
}
